/*
This code is meant to read in, clean and combine PPP data for use on the JCT side and for preparation for fuzzy matching with tax data.
The data was downloaded from the Small Business Association website. It is split into 13 files and we combine it here.
*/

//Read in and save the individual files
import delimited "${datadir}/sba/public_150k_plus_230101.csv", clear


save "${datadir}/sba/public_150k_plus", replace


forvalues file = 1/12 {
	import delimited "${datadir}/sba/public_up_to_150k_`file'_230101.csv", clear


	save "${datadir}/sba/public_up_to_150k_`file'", replace

}


//Append all of the files together
use "${datadir}/sba/public_150k_plus", clear

forvalues file = 1/12 {
	append using "${datadir}/sba/public_up_to_150k_`file'"
}

save "${datadir}/sba/public_all_vars", replace

//Keep only variables we intend to use

keep loannumber dateapproved processingmethod borrowername borroweraddress borrowercity borrowerstate borrowerzip /// 
loanstatus initialapprovalamount currentapprovalamount undisbursedamount franchisename /// 
projectcity projectcountyname projectstate projectzip jobsreported naicscode payroll_proceed /// 
businesstype forgivenessamount forgivenessdate

save "${datadir}/sba/public_all", replace


//Add a variable to the end of the file that is numeric and never missing to avoid possible issue when reading data into SQL
gen safety = 1

export delimited "${datadir}/sba/public_all", replace quote
